package array.leetcode.medium;

/**
 * @author bruin_du
 * @description 构建乘积数组
 * @date 2022/6/5 20:45
 **/
public class Offer66_ConstructArr {
    public int[] constructArr(int[] a) {
        int length = a.length;
        if(length == 0) return new int[0];
        int[] b = new int[length];
        b[0] = 1;
        for (int i = 1; i < length; i++) {
            b[i] = b[i - 1] * a[i - 1];
        }
        int tmp = 1;
        for (int i = length - 2; i >= 0; i--) {
            tmp *= a[i + 1];
            b[i] *= tmp;
        }
        return b;
    }
}
